package com.ts.proj.controller;

import com.ts.base.controller.BaseController;
import com.ts.proj.entity.JijinDetailEntity;
import com.ts.proj.entity.JijinItemEntity;
import com.ts.proj.entity.ProjectMeetingEntity;
import com.ts.proj.service.JijinDetailService;
import com.ts.proj.service.JijinItemService;
import com.ts.util.JurisdictionUtil;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

//说明 字符串：Test，作为替换字符串

@Controller
public class JijinItemController extends BaseController {

    @Autowired
    private JijinItemService jijinItemService;

    @Autowired
    private JijinDetailService jijinDetailService;

    @RequestMapping("/project-jijin-item/{id}")
    public ModelAndView projectFinance(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            modelAndView.addObject("id", id);
            viewName = "business/touhou/jijin-item";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-item-add/{id}")
    public ModelAndView projectFinanceAdd(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            modelAndView.addObject("id", id);
            modelAndView.addObject("localId", -1);
            modelAndView.addObject("item", null);
            viewName = "business/touhou/item-add";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/project-item-edit/{id}")
    public ModelAndView projectFinanceAddEdit(@PathVariable("id") Integer id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            JijinItemEntity jijinItemEntity = jijinItemService.findById(id);
            modelAndView.addObject("id", jijinItemEntity.getProID());
            modelAndView.addObject("localId", id);
            modelAndView.addObject("item", jijinItemEntity);
            viewName = "business/touhou/item-add";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

    @RequestMapping("/jijin-detail-add/{projectId}/{itemId}/{itemDetailId}")
    public ModelAndView jijinDetail(@PathVariable("projectId")Integer projectId,@PathVariable("itemId") Integer itemId,
                                    @PathVariable("itemDetailId") Integer itemDetailId){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            JijinDetailEntity detailEntity = jijinDetailService.findById(itemDetailId);
            modelAndView.addObject("projectId",projectId);
            modelAndView.addObject("itemId", itemId);
            modelAndView.addObject("itemDetailId", itemDetailId);
            modelAndView.addObject("detailEntity",detailEntity);
            viewName = "business/touhou/jijin-detail";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;

    }
    //双击显示备注
    @RequestMapping("/jijinItem-onDbClick-view/{id}")
    public ModelAndView projectDetail(@PathVariable("id") String id){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            JijinItemEntity byId = jijinItemService.findById(Integer.valueOf(id));
            PageData pd = new PageData();
            pd.put("deleteFlag","N");
            pd.put("jijinID",byId.getId());
            List<JijinDetailEntity> jijinDetailEntityList = jijinDetailService.findAll(pd);
            modelAndView.addObject("jijiItem",byId);
            modelAndView.addObject("jijinDetailEntityList",jijinDetailEntityList);
            viewName = "business/touhou/jijinDbClick";
        }
        modelAndView.setViewName(viewName);

        return modelAndView;

    }
}